package com.nantai.jiafang.nantaijiafang.deviceManager.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.nantai.jiafang.nantaijiafang.R;
import com.nantai.jiafang.nantaijiafang.deviceManager.bean.KeepTask;

import java.util.List;

/**
 * Created by xxfreedom on 2017/2/12.
 */

public class KeepTaskAdapter extends BaseAdapter {
    private List<KeepTask> list;
    private LayoutInflater inflater;
    public KeepTaskAdapter() {}

    public KeepTaskAdapter(List<KeepTask> list, Context context) {
        this.list = list;
        this.inflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list==null?0:list.size();
    }

    @Override
    public KeepTask getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //加载布局为一个视图
        View view=inflater.inflate(R.layout.normal_keep_item,null);
        KeepTask task=getItem(position);
        TextView tv_name= (TextView) view.findViewById(R.id.deviceName_tx);
        TextView tv_code= (TextView) view.findViewById(R.id.deviceCode_tx);
        TextView tv_time= (TextView) view.findViewById(R.id.time_tx);
        TextView tv_place= (TextView) view.findViewById(R.id.place_tx);
        tv_name.setText("设备名称:"+task.getName());
        tv_code.setText("设备条码:"+task.getQr_code());
        tv_time.setText("保养时间:"+task.getNext_keep_time());
        tv_place.setText("库位:"+task.getPlace_name());
        return view;
    }
    public void removeItem(int index)
    {
        list.remove(index);
        notifyDataSetChanged();
    }
}
